package prcsupport

import (
	"net"
	"net/http"
	"net/rpc"
)

func ServeRpc(host string, ele interface{}) error {
	e := rpc.Register(ele)
	if e != nil {
		return e
	}
	rpc.HandleHTTP()
	l, e := net.Listen("tcp", host)
	if e != nil {
		return e
	}
	e = http.Serve(l, nil)
	if e != nil {
		return e
	}
	return nil
}
func NewCli(host string) (*rpc.Client, error) {
	client, err := rpc.DialHTTP("tcp", host)
	if err != nil {
		return nil, err
	}
	return client, nil

}
